﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Threading;

namespace EpsiRisk.AffichageJeu
{
    public abstract class ClassZone
    {
        public int height;
        public int width;
        public Vector2 position;
        public Color backcolor;
        public List<ClassBouton> listeBoutons = new List<ClassBouton> { };


        /// <summary>
        /// ajoute un bouton
        /// </summary>
        /// <param name="b"></param>
        public void AddBouton(ClassBouton b)
        {

            listeBoutons.Add(b);
            b.offset = this.position;

        }


        /// <summary>
        /// suprime un bouton
        /// </summary>
        /// <param name="b"></param>
        public void RemoveBouton(ClassBouton b)
        {

            listeBoutons.Remove(b);

        }


        internal virtual void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();
            if (backcolor != Color.TransparentWhite)
            {
                spriteBatch.GraphicsDevice.Clear(ClearOptions.Target, backcolor, 0, 0, new Rectangle[] { new Rectangle((int)position.X, (int)position.Y, width, height) });
            }
            spriteBatch.End();
            foreach (ClassBouton b in listeBoutons)
            {
                b.Draw(spriteBatch);
            }
        }

        internal virtual void clicXY(int x, int y)
        {
            foreach (ClassBouton z in listeBoutons)
            {
                if (z != null)
                {
                    if (z.position.X <= x && x <= z.position.X + z.width && z.position.Y <= y && y <= z.position.Y + z.height)
                    {
                        z.clicXY(x - (int)z.position.X, y - (int)z.position.Y);
                    }
                }
            }
        }

        internal virtual void initialiser(Microsoft.Xna.Framework.Content.ContentManager content) { }
    }
}
